package org.hrc.puzzleGame.controller;

import org.hrc.puzzleGame.mapper.UserMapper;
import org.hrc.puzzleGame.mapper.impl.UserMapperImpl;
import org.hrc.puzzleGame.model.User;
import org.hrc.puzzleGame.util.Globals;

import java.sql.SQLException;
import java.util.Objects;

public class LoginController {
    private static UserMapper userMapper = new UserMapperImpl();

    public boolean login(User user) throws SQLException {
        User queryUser = userMapper.queryByName(user.getUserName());
        System.out.println(queryUser);
        // 用户不存在
        if (Objects.isNull(queryUser))
            return false;
        //密码错误
        if (!user.getPassword().equals(queryUser.getPassword()))
            return false;
        Globals.user = queryUser;
        return true;
    }
}
